package com.briup.cms.web.controller;

import com.briup.cms.service.IUploadLocalService;
import com.briup.cms.service.IUploadRemoteService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "文件上传模块,使用POSTMAN测试")
@RestController
@RequestMapping("/upload")
public class UploadController {
    @Autowired
    private IUploadRemoteService uploadRemoteService;

    @Autowired
    private IUploadLocalService uploadLocalService;

    @PostMapping(value="/remote",consumes = "multipart/form-data")
    @ApiOperation("上传文件并返回文件地址，上传到远程的OSS服务器或者fastDFS服务器上")
    @ApiImplicitParams(
            @ApiImplicitParam(name="files",value="文件",paramType = "form",dataType = "__file",allowMultiple = true)
    )
    public Message uploadFileRemote(@RequestParam("files") MultipartFile[] files){
        return MessageUtil.success(uploadRemoteService.uploadRemoteFile(files));
    }

    @PostMapping(value="/local",consumes = "multipart/form-data")
    @ApiOperation("上传文件，上传到部署服务器本地")
    @ApiImplicitParams(
            @ApiImplicitParam(name="files",value="文件",paramType = "form",dataType = "__file",allowMultiple = true)
    )
    public Message uploadFileLocal(@RequestParam("files") MultipartFile[] files){
        return MessageUtil.success(uploadLocalService.uploadLocalFile(files));
    }

    @PostMapping(value="/local/args",consumes = "multipart/form-data")
    @ApiOperation("上传文件，上传到部署服务器本地,上传时可以携带其他参数，当前该接口用不到，没有实现，本地上传使用不带额外参数的上传接口即可")
    @ApiImplicitParams({
            @ApiImplicitParam(name="files",value="文件",paramType = "form",dataType = "__file",allowMultiple = true),
            @ApiImplicitParam(name="args",value="其他参数",paramType = "form",dataType = "String"),
    })
    public Message uploadFileLocalWithArgs(@RequestParam("files") MultipartFile[] files,@RequestParam("args") String args){
        return MessageUtil.success(uploadLocalService.uploadLocalFileWithArgs(files,args));
    }




}
